Skip to content

perf(aot): use checked native atomics for ordered scalar accesses - #4813

Closed
yabanana wants to merge 321 commits into
boykopovar:mainfrom
yabanana:feature/aot-ordered-access-fastpath
Closed

yabanana wants to merge 321 commits into
boykopovar:mainfrom
yabanana:feature/aot-ordered-access-fastpath

Conversation

@yabanana

Copy link
Copy Markdown
Contributor

What

Avoid full barriers around every naturally aligned scalar access in the concurrent guest-state profile. Check alignment, then emit volatile sequentially consistent LLVM loads/stores; retain the fenced path for unaligned addresses and the existing guards on locked operations. The concurrent profile selects this implementation by default; --ordered-access fenced remains the reference. Preserve ordering at native provider/callback boundaries and CPUID. Descriptor version 5 requires regenerated objects.

This keeps the conservative qualified memory profile. It does not infer private buffers, relax synchronization to RCpc or provide general mixed-width/vector race support. AArch64 SC instruction mapping reference: https://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html.

Add an optional benchmark harness for supplied zstd executables. It checks architecture, compressed-output equality and a separate decoder before alternating timed runs. It records artifact hashes, CPU/wall time and peak RSS; source/feature equivalence remains a separate qualification.

Tested

Apple Silicon macOS: 609 compiler/relinker/runtime tests passed. Ordered-access tests include aligned/unaligned widths, synchronized worker starts, store buffering with/without fences, message passing, IRIW, atomic publication, CPUID ordering and invalid configuration rejection. These are bounded observations, not a universal concurrency proof.

Zstd 1.5.7 from the same x86-64 glibc ELF: 18 cases with 1/2/4 workers and 61 broader CLI/error/dictionary cases match the source-built ARM64 reference and independent decoder checks. On the 128 MiB mixed corpus at level 3 with two workers, nine alternating warmed runs give medians of 35.08 ms for this checkpoint and 80.29 ms for the preceding fenced implementation (about 2.29x). The source-equivalent x86 Mach-O reference under Rosetta, compiled O3+ThinLTO, takes 33.67 ms: AOT remains about 4.2% slower on this workload. No general Rosetta speedup or game claim is made. These CLI measurements include startup/I/O and do not establish cold-cache behavior.

The graphics base is unchanged from the verified #4740 base. Weaker-order, LSE2 and AOT ThinLTO experiments were retained outside the patch because they did not demonstrate a clear benefit on this workload.

Checklist

Read PT_GNU_EH_FRAME, the eh_frame stream, PT_DYNAMIC and the ELF entry
through program headers only. Every FDE must match its search-table key and
lie in one executable file-backed segment; unsorted or duplicate tables,
extended records, foreign return columns and out-of-image pointers are
rejected. Overlapping ranges, unindexed FDEs, a missing index and an
unterminated stream become explicit obligations instead of guessed ranges.

The load-fact dossier records entry, lifecycle, export and address-taken
roots, direct calls, PLT and GOT import bindings with provenance,
preconditions, dependencies and invalidation conditions. Indirect transfers,
tail calls, interior calls and unclassified executable bytes stay
obligations. recover_image consumes the qualified ranges and dynamic symbols
so the same image recovers identically with or without a section table.
…nges

recover_image read the unwind index without relocation bindings, so every
FDE whose CIE names its personality through a relocated slot was rejected
while the load-fact dossier qualified the same ranges. A statically linked
C++ runtime produced 483 such ranges. Pass the dynamic relocation slots to
the unwind reader; a slot without a relocation still leaves the range
unqualified.
Images linked with only DT_GNU_HASH and no section table were rejected for
lacking a bounded symbol count. Walk the GNU hash chain from the largest
bucket through mapped memory until its end bit, require buckets at or above
the symbol offset, and keep the existing agreement check when DT_HASH is
also present. Register the load-fact tests on every native AOT host.
Add a separate lowering mode for complete position-independent images.
Every recovered unit becomes one ARM64 function over the guest register
state and the guest stack, so internal functions keep their original
calling convention and need no declared C signature. The image is mapped
from its loadable bytes with RELATIVE relocations, RELRO and per-page
permissions; imports resolve to provider thunks at reserved addresses.

Calls write the guest return address and continue only when the callee
returns to it; any other address propagates and traps at the top level.
Indirect transfers go through a finite entry table and trap on unknown
targets. Jump tables use a bound proven by cmp/ja and zero extension, or
an extent read from immutable data inside the unwind range that stays a
candidate with a runtime membership check. Units reject flags read at
entry or after a call, unimplemented instructions and undecodable code.
Calls to imports declared noreturn in the glibc catalog end their path.

Instruction semantics cover the integer, BMI1/BMI2, string and SSE/SSE2
forms used by the corpus, with x86 behaviour where LLVM leaves results
undefined: masked shift counts, preserved flags for zero counts, divide
traps, bit scans of zero, the integer indefinite value and x86 NaN
propagation. A lab compares 612 instruction forms against x86_64 code
run under Rosetta. The glibc x86-64 provider for Darwin converts stat and
dirent layouts, errno values, open, mmap, clock and *at constants, signal
numbers, System V variadic arguments and guest callbacks.
ps5link writes a four-byte PT_GNU_EH_FRAME at address 0 whose file offset is
not the loaded offset of that address, so the reader decoded code bytes as
an eh_frame_hdr and rejected the image. Require the header's file offset to
match the PT_LOAD mapping of its address; otherwise report
unwind-index-not-loaded and recover no unwind ranges from it.
# Conflicts:
#	core/libs/prx/libSceAgcDriver/PostCompile.cmake
…owering

Extend guest-state lowering to statically linked C++ programs whose own
libunwind and libc++abi unwind the guest stack.

LSDA call-site tables give each unit its landing pads. A unit whose call
returns an address other than the pushed one first checks its landing
pads and its own call-return addresses, then propagates; an indirect jump
to an address without a converted entry propagates the same way. The
guest unwinder's register restore therefore resumes at the landing pad in
the frame that owns it, and longjmp-style transfers resume at a call
return. Units share one resume dispatcher to keep the CFG linear.

Locked add/sub/and/or/xor/inc/dec/xadd/xchg/cmpxchg lower to seq_cst
atomicrmw or cmpxchg with x86 flags and trap when the access crosses its
natural alignment. Unlocked xadd and cmpxchg follow the same semantics.
x87 loads and stores of 80-bit values move bytes on a stack kept in the
guest state, so long double values cross calls unchanged; conversions and
arithmetic still reject. PT_TLS gets a variant II thread area with the
self pointer and stack guard of the glibc TCB. Jump-table bases held in
callee-saved registers are followed across calls.

The glibc provider adds the C locale with glibc ctype tables and
locale_t layout, wide-character conversions, varargs from a guest
va_list, sscanf, swprintf, pthread mutex/rwlock/condition side tables,
futex, gettid and getrandom system calls, dl_iterate_phdr, dladdr and
dlsym over the image exports, and __cxa_atexit.
This was referenced Oct 15, 2026
@ArjenS-LA ArjenS-LA mentioned this pull request Oct 15, 2026
11 tasks done
@yabanana

Copy link
Copy Markdown
Contributor Author

Superseded by #5021, which now contains the consolidated native ARM64 AOT implementation and verified consumers. #1835 remains the architecture discussion. Closing this stacked PR to keep one implementation review; its branch and review history are retained. This is not a merge into main.

@yabanana yabanana closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build ci .github docs libc libkernel needs rebase Conflicts with main, rebase needed prx relinker shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant